from bs4 import BeautifulSoup
soup = BeautifulSoup('<p>Hello</p>','lxml')
print(soup.p.string)
html = '''
<html><head><title>The Dormouse's story</title></head>
<body>
<p class="title" name="dromouse"><b>The Dormousr's story</b></p>
<p class = "story">Once upon a time there were three little sisters;and their names were
<a href = "http://example.com/elsie" class="sister" id ="link1><!--Elsie--></a>,
<a href = "http://example.com/lacie" class="sister" id ="link2>Lacie</a>and
<a href = "http://example.com/tillie" class="sister" id ="link3>Tillie</a>;
and they lived at the bottom of a well.</p>
<p class="story">...</p>
'''
soup = BeautifulSoup(html,'lxml')#html是一个HTML字符串，lxml类型的解析器，完成了Beatifulsoup对象的初始化
print(soup)
print('*************')
print(soup.prettify())#prettify方法可以把要解析的字符串以标准的缩进格式输出
print('------------')
print(soup.title)
print('+++++++++++++')
print(soup.title.string)#获取title节点的文本内容
# 选择元素
soup = BeautifulSoup(html,'lxml')
print(soup.title)
print(type(soup.title))
print(soup.title.string)
print(soup.head)
print(soup.p)#选第一个匹配到的节点，其后面的都会被忽略
# 提取信息
# 获取名称，获取节点名称
print(soup.title.name)
# 获取属性
print(soup.p.attrs)#返回字典形式
print(soup.p.attrs['name'])
print(soup.p)
print(soup.p['name'])
print(soup.p['class'])
# 获取内容
print(soup.p.string)
